import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_shop/model/details.dart';
import 'package:flutter_shop/provide/cart.dart';
import 'package:flutter_shop/provide/currentIndex.dart';
import 'package:flutter_shop/provide/details_provide.dart';
import 'package:flutter_shop/routers/fluro_navigator.dart';
import 'package:provide/provide.dart';

class DetailsBottom extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Provide<DetailsInfoProvide>(
      builder: (context, child, details) {
        GoodInfo goodInfo = details.detailsModel.data.goodInfo;

        return Container(
          color: Colors.white,
          width: ScreenUtil().setWidth(750),
          child: Row(
            children: <Widget>[
              InkWell(
                onTap: () {
                  Provide.value<CurrentIndex>(context).currentIndex(2);
                  NavigatorUtils.goBack(context);
                },
                child: Container(
                  height: ScreenUtil().setHeight(70.0),
                  decoration: BoxDecoration(
                      border: Border(
                          top: BorderSide(color: Colors.black12, width: 0.5))),
                  width: ScreenUtil().setWidth(110),
                  child: Stack(
                    children: <Widget>[
                      Icon(
                        Icons.shopping_cart,
                        color: Colors.pink,
                        size: 35,
                      ),
                      Positioned(
                        width: ScreenUtil().setHeight(30.0),
                        height: ScreenUtil().setHeight(30.0),
                        child: Container(
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                            color: Colors.red,
                            shape: BoxShape.circle
                          ),
                          child: Provide<CartProvide>(
                            builder: (context,child,cartInfo){
                              return Text(
                                '${cartInfo.AllGoodsCount}',
                                style: TextStyle(color: Colors.white),
                              );
                            },
                          ),
                        ),
                        left: 25.0,
                        top: 1.0,
                      )
                    ],
                  ),
                ),
              ),
              InkWell(
                onTap: () async {
                  await Provide.value<CartProvide>(context).save(
                      goodsId: goodInfo.goodsId,
                      goodsName: goodInfo.goodsName,
                      count: 1,
                      price: goodInfo.oriPrice,
                      images: goodInfo.image1);
                },
                child: Container(
                  height: ScreenUtil().setHeight(70.0),
                  alignment: Alignment.center,
                  width: ScreenUtil().setWidth(320),
                  color: Colors.green,
                  child: Text(
                    '加入购物车',
                    style: TextStyle(
                        fontSize: ScreenUtil().setSp(25.0),
                        color: Colors.white),
                  ),
                ),
              ),
              InkWell(
                onTap: () async {
                  await Provide.value<CartProvide>(context).remo();
                },
                child: Container(
                  height: ScreenUtil().setHeight(70.0),
                  alignment: Alignment.center,
                  width: ScreenUtil().setWidth(320),
                  color: Colors.deepOrange,
                  child: Text(
                    '立刻购买',
                    style: TextStyle(
                        fontSize: ScreenUtil().setSp(25.0),
                        color: Colors.white),
                  ),
                ),
              ),
            ],
          ),
        );
      },
    );
  }
}
